package org.idea.spring.bean.beandefinitionbuilder;

import org.springframework.beans.MutablePropertyValues;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.GenericBeanDefinition;
import org.springframework.core.io.Resource;

/**
 * @Author idea
 * @Date created in 7:51 上午 2020/6/2
 */
public class BeanDefinitionDemo {

    public static void main(String[] args) {
        BeanDefinitionBuilder beanDefinitionBuilder = BeanDefinitionBuilder.genericBeanDefinition(User.class);
        beanDefinitionBuilder
                .addPropertyValue("name", "idea")
                .addPropertyValue("id", 1);
//        beanDefinitionBuilder.setLazyInit(true);
        beanDefinitionBuilder.addConstructorArgValue(2);
        beanDefinitionBuilder.addConstructorArgValue("ttt");
        BeanDefinition userBeanDefinition = beanDefinitionBuilder.getBeanDefinition();
        String[] dependsOn = userBeanDefinition.getDependsOn();


        System.out.println(dependsOn);
        String methodName = userBeanDefinition.getInitMethodName();
        System.out.println(methodName);

        BeanDefinition beanDefinition = beanDefinitionBuilder.getBeanDefinition();
        String beanClass = beanDefinition.getBeanClassName();
        System.out.println(beanClass);

        GenericBeanDefinition genericBeanDefinition = new GenericBeanDefinition();
        genericBeanDefinition.setBeanClass(User.class);

        MutablePropertyValues mutablePropertyValues = new MutablePropertyValues();
        mutablePropertyValues.add("id", 2).add("name", "idea");

        genericBeanDefinition.setPropertyValues(mutablePropertyValues);
        BeanDefinition beanDefinition1 = genericBeanDefinition.getOriginatingBeanDefinition();
        System.out.println(beanDefinition1.getBeanClassName());

    }
}
